package com.xiaochong.tir.manager.controller;

import com.alibaba.fastjson.JSON;
import com.xiaochong.service.common.config.oss.OSSTool;
import com.xiaochong.tir.common.data.po.Report;
import com.xiaochong.tir.manager.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.avro.data.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.common.data.po.NonListedCompanyIndex;
import com.xiaochong.tir.common.data.po.SyResearchReportFile;
import com.xiaochong.tir.common.data.po.SyRotationMap;
import com.xiaochong.tir.manager.service.SyResearchReportFileService;
import com.xiaochong.tir.manager.util.ReturnResult;

/**
 * 数据报表
 */
@Controller
@RequestMapping("/manage/report")
@Api("数据报表")
public class ReportController {
	
	@Autowired
	private ReportService reportService;
	@Autowired
	private OSSTool ossTool;
	
	@GetMapping("/reportPage")
    public String industryList(){
        return "/report/reportsPage";
    }

	/**
	 * 数据报表
	 * @param report
	 * @return
	 */
	@ApiOperation(value = "每日生成的大盘数据Excel下载列表",notes = "每日生成的大盘数据Excel下载列表")
	@PostMapping("/listReport")
	@ResponseBody
	public Object listReport(Report report) {
		try {
			PageInfo<Report> info = reportService.findList(report);
			for (int i = 0; i < info.getList().size(); i++) {
				Report rp = info.getList().get(i);
				rp.setFilePath(ossTool.getOSSUrl(rp.getReportName()));
			}
			return new ReturnResult<Report>(0, "查询成功！", info.getList(), info.getTotal());
		} catch (Exception e) {
			e.printStackTrace();
			LogTrace.error(getClass().getSimpleName() + ".listReport()", e.getMessage(), e);
			return new ReturnResult<Report>(-1, "查询失败！",1, 1);
		}
	}

}
